import { reqGoodsInfo, reqAddOrUpdataShopCart } from "@/api";
import { getUUID } from '@/utils/uuid_token'
const state = {
    goodInfo: {},
    uuid_token: getUUID()
}
const mutations = {
    GETGOODINFO(state, goodInfo) {
        state.goodInfo = goodInfo;
    }

}
const actions = {
    async getGoodInfo({ commit }, skuId) {
        let result = await reqGoodsInfo(skuId);

        if (result.code === 200) {
            commit("GETGOODINFO", result.data)
        }
    },
    // 将产品加入到购物车信息中
    async addOrUpdataShopCart({ commit }, { skuId, skuNum }) {
        let result = await reqAddOrUpdataShopCart(skuId, skuNum);

        if (result.code === 200) {
            return 'ok'
        } else {
            return Promise.reject(new Error('失败123'))
        }

    }
}
const getters = {
    //简化数据
    //路径导航
    categoryView(state) {
        return state.goodInfo.categoryView || {};
    },
    //产品信息
    skuInfo(state) {
        return state.goodInfo.skuInfo || {};
    },
    //产品售卖属性
    /* skuSaleAttrValueList(state) {
        return state.goodInfo.skuInfo.skuSaleAttrValueList || []
    } */

}
export default {
    state, mutations, actions, getters

}